package cn.edu.hzw.comic

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.webkit.*
import kotlinx.android.synthetic.main.activity_about.*
import org.jetbrains.anko.image

class AboutActivity : AppCompatActivity() {
    companion object{
        const val TYPE_MY:String = "my"
        const val TYPE_ROOM:String = "room"
        const val TYPE:String = "Type"

    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_about)
        var type = intent.getStringExtra(TYPE)
        initView()
        if (type.equals(TYPE_MY)){
            collapsingToolbar.title = getString(R.string.about_one)
            imageView.image = resources.getDrawable(R.mipmap.my)
            webView.loadUrl("https://github.com/2796859746")
        }else if (type.equals(TYPE_ROOM)){
            collapsingToolbar.title = getString(R.string.about_two)
            imageView.image = resources.getDrawable(R.mipmap.room)
            webView.loadUrl("https://blog.csdn.net/qq_39485117")
        }
    }

    private fun initView() {
        setSupportActionBar(toolbar_about)
        toolbar_about.setOnClickListener{
            val intent:Intent = Intent(this,MainActivity::class.java)
            startActivity(intent)
        }
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        webView.settings.setSupportZoom(true)
        webView.settings.builtInZoomControls = true
        webView.settings.useWideViewPort = true
        webView.settings.javaScriptEnabled = true
        webView.settings.loadWithOverviewMode = true
        webView.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
        webView.settings.loadWithOverviewMode = true
        webView.webViewClient = object : WebViewClient() {

            override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
                return false
            }

        }
        webView.webChromeClient = object:WebChromeClient(){
            override fun onProgressChanged(view: WebView?, newProgress: Int) {
                if (newProgress == 100){
                    progressBar1.visibility = View.GONE
                }else{
                    progressBar1.visibility = View.VISIBLE
                    progressBar1.progress = newProgress
                }
            }
        }


    }
}